$(function () {
    picMax=30;
    isReUplod=false;
    loadData()

    /***
     * 拖拽功能
     */
    dragula([document.getElementById('dragBox')]);
})

function loadData(){
    var url= baseQuestionUrl+'slideshow'
    ajaxCommon.request('get',url,{},function(res){
        if(res.code===200){
            // var arr=['https://1120564654-1256241692.cos.ap-shanghai.myqcloud.com/mydesk.jpg','https://1120564654-1256241692.cos.ap-shanghai.myqcloud.com/640x960.png','https://1120564654-1256241692.cos.ap-shanghai.myqcloud.com/828x1792.png','https://1120564654-1256241692.cos.ap-shanghai.myqcloud.com/1242x2688.png','https://1120564654-1256241692.cos.ap-shanghai.myqcloud.com/828x1792.png']
            res.data.map((item,index)=>{
                createPic(true)
                $('.zz-box:eq('+index+')').children('.prePic').css({
                    background: 'url("' + item + '") center no-repeat',
                    backgroundSize: 'cover'
                })
                $('.zz-box:eq('+index+')').children('.picUrl').val(item)

            })
            createPic()
        }
    })
}

function submit(){
    var url = baseQuestionUrl+'update/slideshow'
    var arr=''
    var obj=$('.zz-box')
    for (var i=0;i<obj.length;i++){
        if($('.zz-box:eq('+i+')').children('.picUrl').val()) {
            arr+=$('.zz-box:eq(' + i + ')').children('.picUrl').val()+','
        }
    }
    arr=arr.substr(0,arr.length-1)
    var submitObj=JSON.stringify(arr)
    ajaxCommon.request('post',url,submitObj,function(res){
        if(res.code===200 && res.data === 'ok'){
            swal("更新！", "当前记录更新成功！", "success");
        }
    })
}
